import { orderStatusList } from '@/enums/orderEnum';
import { handleAddrText } from '@/hooks/web/useCommon';
import { deliveryMethodList } from '@/enums/productionEnum';
import { BasicColumn, FormSchema } from '@/components/Table';
import { SpecValueModel } from 'mc-c2b2m-operator-api/types/order';

function handleSpecValueList(list: SpecValueModel[]) {
  let text: string = '';
  list?.forEach?.((item) => {
    const { spuSpecName: name, spuSpecValueName: val } = item;
    text += `${text ? '+' : ''}${name}(${val})`;
  });
  return text;
}
export const tableColumns: BasicColumn[] = [
  { width: 150, title: '产品单号', dataIndex: 'orderCode' },
  {
    width: 100,
    title: '状态',
    dataIndex: 'status',
    slots: { customRender: 'status' },
  },
  { width: 180, title: '支付时间', dataIndex: 'paidTime' },
  { width: 130, title: '下单手机号', dataIndex: 'orderPlacerUserPhone' },
  { title: '推荐人', dataIndex: 'referrerUserName' },
  { title: '产品名称', dataIndex: 'spuName' },
  { width: 100, title: '数量', dataIndex: 'quantity' },
  { width: 120, title: '展开尺寸', dataIndex: 'productMeasure' },
  {
    title: '材质',
    dataIndex: 'materialSpecValueList',
    customRender: ({ text }) => handleSpecValueList(text),
  },
  {
    title: '印刷',
    dataIndex: 'printingSpecValueList',
    customRender: ({ text }) => handleSpecValueList(text),
  },
  {
    title: '工艺',
    dataIndex: 'processSpecValueList',
    customRender: ({ text }) => handleSpecValueList(text),
  },
  { width: 140, title: '订单金额（元）', dataIndex: 'settlementAmount' },
  { width: 140, title: '实收金额（元）', dataIndex: 'paidAmount' },
  { width: 140, title: '商品金额（元）', dataIndex: 'sellingAmount' },
  { width: 120, title: '税金（元）', dataIndex: 'taxAmount' },
  { width: 140, title: '调整金额（元）', dataIndex: 'adjustmentAmount' },
  { width: 120, title: '邮费（元）', dataIndex: 'logisticsFee' },
  {
    width: 120,
    title: '提货方式',
    dataIndex: 'deliveryMethod',
    customRender({ record }) {
      const { deliveryMethod } = record?.logisticsBill || {};
      return deliveryMethodList.find((find) => find.value === deliveryMethod)?.label;
    },
  },
  {
    title: '提货地址',
    dataIndex: 'addr',
    customRender: ({ record }) => {
      return handleAddrText(record?.logisticsBill || {});
    },
  },
  {
    title: '提货联系人',
    dataIndex: 'consigneeName',
    customRender: ({ record }) => {
      return record.logisticsBill?.consigneeName;
    },
  },
  {
    width: 130,
    title: '提货联系电话',
    dataIndex: 'consigneePhone',
    customRender: ({ record }) => {
      return record.logisticsBill?.consigneePhone;
    },
  },
];
export const tableFormSchema: FormSchema[] = [
  {
    field: 'orderCode',
    label: '产品单号',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'orderPlacerUserPhone',
    label: '下单手机号',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'orderTime',
    label: '下单时间',
    component: 'RangePicker',
    colProps: { span: 6 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: orderStatusList,
    },
  },
];

export const abstractList = [
  { label: '订单数', key: 'orderNum' },
  { label: '下单用户数', key: 'customerNum' },
  { label: '实收总金额（元）', key: 'paidAmount' },
];
